# Maintainer: Mario Emmenlauer <memmenlauer@biodataanalysis.de>

_realname=matio
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.5.19
pkgrel=1
pkgdesc="matio is a C library for reading and writing MATLAB MAT files (mingw-w64)"
arch=('any')
url='https://sourceforge.net/projects/matio/'
license=('Simplified BSD')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-hdf5")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs' 'strip')
source=(https://downloads.sourceforge.net/project/matio/matio/${pkgver}/matio-${pkgver}.7z)
sha256sums=('6e409cc6f3fdd9c8e7b0acbe67cc6e71a312729226169e91874bc519cfc4993c')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  cp -rf "${_realname}-${pkgver}" "build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  chmod +x ./configure
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --disable-debug \
    --enable-mat73="yes" \
    --with-default-file-ver="7.3"

  make ${MAKEFLAGS}
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  # it is not clear why the following workaround is needed to
  # execute tests, but after touching the testsuite.at, the
  # tests work, when otherwise they fail:
  touch ./test/testsuite.at

  make check
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" -j1 install

  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/"
}
